package com.jf.ss.base.controller;

import com.jf.ss.base.pojo.Label;
import com.jf.ss.base.service.LabelService;
import com.jf.ss.common.entity.Result;
import com.jf.ss.common.entity.StatusCode;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/label")
public class LabelController {
    @Resource
    LabelService labelService;

    @PostMapping
    public Result insert(@RequestBody Label label) {
        labelService.insert(label);
        return new Result(true, StatusCode.OK, "操作成功");
    }

    @DeleteMapping(value = "/{labelId}")
    public Result delete(@PathVariable("labelId") String id) {
        labelService.delete(id);
        return new Result(true, StatusCode.OK, "操作成功");
    }

    @PutMapping(value = "/{labelId}")
    public Result update(@PathVariable("labelId") String id, @RequestBody Label label) {
        label.setId(id);
        labelService.update(label);
        return new Result(true, StatusCode.OK, "操作成功");
    }

    @GetMapping(value = "/{labelId}")
    public Result findById(@PathVariable("labelId") String id) {
        Label label = labelService.findById(id);
        return new Result(true, StatusCode.OK, "操作成功",label);
    }
    @GetMapping
    public Result findAll() {
        List<Label> labelList = labelService.findAll();
        return new Result(true, StatusCode.OK, "操作成功",labelList);
    }


}
